package com.yloveg.common;

import java.util.LinkedHashMap;
import java.util.Map;

public class FreemarkUtil {
	
/**
 * 1 是否
 * @author Administrator
 *
 */
	public enum YesOrNo {
		YES("是","1"),
		NO("否","2");
		private String name;  
	    private String value;  
	    // 构造方法  
	    private YesOrNo(String name, String value) { 
	    	this.name = name;
	        this.value = value;  
	          
	    }
		public String getname() {
			return name;
		}
		public void setname(String name) {
			this.name = name;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}
	//后台调用
    public static String YesOrNoNmame(String value) {  
        for (YesOrNo b : YesOrNo.values()) {  
            if (b.getValue().equals(value) ) {  
                return b.name;
            }  
        }  
      return null;  
    } 
	/**
	 * 2状态
	 * @author Administrator
	 *
	 */
	public enum State {
		IN_AUDIT("审核中","2"),
		PASS("通过","1"),
		NO_PASS("未通过","0");
		private String name;  
	    private String value;  
	    // 构造方法  
	    private State(String name, String value) { 
	    	this.name = name;
	        this.value = value;  
	          
	    }
		public String getname() {
			return name;
		}
		public void setname(String name) {
			this.name = name;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}
	//后台调用
    public static String getStateName(String value) {  
        for (State b : State.values()) {  
            if (b.getValue().equals(value) ) {  
                return b.name;
            }  
        }  
      return null;  
    } 
	
/**
 * 3商品类别
 * @author Administrator
 *
 */
	public enum ProductType {
		FRUITS("干鲜果","1"),
		GREENS("干鲜菜","2"),
		CRUDE_DRUGS("药材","3"),
		AQUATIC_PRODUCT("水产品","4"),
		PRODUCT_OTHER("其他","20");
		private String name;  
	    private String value;  
	    // 构造方法  
	    private ProductType(String name, String value) { 
	    	this.name = name;
	        this.value = value;  
	          
	    }
		public String getname() {
			return name;
		}
		public void setname(String name) {
			this.name = name;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}
	//后台调用
    public static String ProductTypeNmame(String value) {  
        for (ProductType b : ProductType.values()) {  
            if (b.getValue().equals(value) ) {  
                return b.name;
            }  
        }  
      return null;  
    }
    
/**
 *4支付类型
 * @author Administrator
 *
 */
	public enum PaymentType {
		ZFBH5("支付宝H5","1"),
		ZFBAPP("支付宝APP","2"),
		WXH5("微信H5","3"),
		WXAPP("微信APP","4"),
		WXZZ("微信转账","5");
		
		private String name;  
	    private String value;  
	    // 构造方法  
	    private PaymentType(String name, String value) { 
	    	this.name = name;
	        this.value = value;  
	          
	    }
		public String getname() {
			return name;
		}
		public void setname(String name) {
			this.name = name;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}
	//后台调用
    public static String PaymentTypeNmame(String value) {  
        for (PaymentType b : PaymentType.values()) {  
            if (b.getValue().equals(value) ) {  
                return b.name;
            }  
        }  
      return null;  
    }  

/**
 *5订单状态
 * @author Administrator
 *
 */
	public enum OrderStatus {
        TOBECONFIRM("待确认","0"),
		PENDINGPAY("待付款","1"),
		TOBESHIPPED("待发货","2"),
		TOBERECEIVED("待收货","3"),
		TOBEEVALUATED("已完成","4");
		
		private String name;  
	    private String value;  
	    // 构造方法  
	    private OrderStatus(String name, String value) { 
	    	this.name = name;
	        this.value = value;  
	          
	    }
		public String getname() {
			return name;
		}
		public void setname(String name) {
			this.name = name;
		}
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
	}
	//后台调用
    public static String OrderStatusNmame(String value) {  
        for (OrderStatus b : OrderStatus.values()) {  
            if (b.getValue().equals(value) ) {  
                return b.name;
            }  
        }  
      return null;  
    } 
    
    /**
     *6物流信息
     * @author Administrator
     *
     */
    	public enum WlCompany {
    		EMS("EMS","EMS"),
    		ANE("安能","ANE"),
    		ANEEX("安能快递","ANEEX"),
    		HTKY("百世快递","HTKY"),
    		BSKY("百世(汇通)快运","BSKY"),
    		DEPPON("德邦","DEPPON"),
    		JD("京东","JD"),
    		STO("申通","STO"),
    		SDEX("顺达快递","SDEX"),
    		SFEXPRESS("顺丰","SFEXPRESS"),
    		SUNING("苏宁","SUNING"),
    		CHINAPOST("邮政包裹","CHINAPOST"),
    		YTO("圆通","YTO"),
    		YUNDA("韵达","YUNDA"),
    		ZJS("宅急送","ZJS"),
    		ZTO("中通","ZTO"),
    		ZTO56("中通快运","ZTO56"),
    		INTMAIL("邮政国际包裹","INTMAIL"),
    		FEDEX("联邦快递","FEDEX");
    		
    		private String name;  
    	    private String value;  
    	    // 构造方法  
    	    private WlCompany(String name, String value) { 
    	    	this.name = name;
    	        this.value = value;  
    	          
    	    }
    		public String getname() {
    			return name;
    		}
    		public void setname(String name) {
    			this.name = name;
    		}
    		public String getValue() {
    			return value;
    		}
    		public void setValue(String value) {
    			this.value = value;
    		}
    	}
    	//后台调用
        public static String WlCompanyNmame(String value) {  
            for (WlCompany b : WlCompany.values()) {  
                if (b.getValue().equals(value) ) {  
                    return b.name;
                }  
            }  
          return null;  
        } 
        
    	/**
    	 * 7邮件发送类型
    	 * @author Administrator
    	 *
    	 */
    	public enum MailType {
    		REGISTER("注册","1"),
    		FORGET_PWD("忘记密码","2");
    		private String name;  
    	    private String value;  
    	    // 构造方法  
    	    private MailType(String name, String value) { 
    	    	this.name = name;
    	        this.value = value;  
    	          
    	    }
    		public String getname() {
    			return name;
    		}
    		public void setname(String name) {
    			this.name = name;
    		}
    		public String getValue() {
    			return value;
    		}
    		public void setValue(String value) {
    			this.value = value;
    		}
    	}
    	//后台调用
        public static String getMailTypeName(String value) {  
            for (MailType b : MailType.values()) {  
                if (b.getValue().equals(value) ) {  
                    return b.name;
                }  
            }  
          return null;  
        }         
    
	    /*************************************下拉表*************************************************/
	    
	    /**
	     * 枚举数据获取
	     */
	    private static Map<Object, Object> getSelectData(String type){
	    	Map<Object, Object> dataMap = new LinkedHashMap<Object, Object>();
	    	//是否
	    	if(type.equals("yesOrNo")){
	    		YesOrNo[] yesOrNo = YesOrNo.values();
	    		for (YesOrNo temp : yesOrNo) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//通过状态
	    	if(type.equals("state")){
	    		State[] state = State.values();
	    		for (State temp : state) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}	
	    	//商品类型
	    	if(type.equals("productType")){
	    		ProductType[] productType = ProductType.values();
	    		for (ProductType temp : productType) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//支付类型
	    	if(type.equals("paymentType")){
	    		PaymentType[] paymentType = PaymentType.values();
	    		for (PaymentType temp : paymentType) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//订单类型
	    	if(type.equals("orderStatus")){
	    		OrderStatus[] orderStatus = OrderStatus.values();
	    		for (OrderStatus temp : orderStatus) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//快递类型
	    	if(type.equals("wlCompany")){
	    		WlCompany[] wlCompany = WlCompany.values();
	    		for (WlCompany temp : wlCompany) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//邮件发送类型
	    	if(type.equals("mailType")){
	    		MailType[] mailType = MailType.values();
	    		for (MailType temp : mailType) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}	
	    	return dataMap;
	    }
		/**
		 * 获取枚举类型下拉表
		 * @param type：字典类型
		 * @param value：值
		 * @return
		 */
		public static  String getOption(String type,String value){
			Map<Object, Object> dataMap = getSelectData(type);
			return option(dataMap,value);
		}
		public static String option(Map<Object, Object> dataMap,String isvalue){
			StringBuilder sb = new StringBuilder();
			if(dataMap.size() > 0 && dataMap != null){
				sb.append("<option value='' >---请选择---</option>");
				for (Object temp : dataMap.keySet()) {
					String value = dataMap.get(temp).toString();
					String name = temp.toString();
					sb.append("<option value='").append(value).append("'");
					if(value.equals(isvalue)){
						sb.append(" selected='selected'");
					}
					sb.append(">").append(name).append("</option>");
				}
			}
			
			return sb.toString();		
		}
		
}
